package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 代售景点的门票信息
 */
@Getter
@Setter
@ToString
public class ScenicTicket {
    //编号
    private Long id;
    //景点名字
    private String name;
    //封面
    private String coverUrl;
    //价格
    private BigDecimal price;
    //地址
    private String address;
    //晋点的评分级别
    private Integer grade;          //景点的状态
    //关联的地区
    private Region region;
    //折扣
    private Double cutoff;
    //介绍
    private String intro;
    //门票时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date time;


    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        map.put("coverUrl", coverUrl);
        map.put("price", price);
        if (region != null) {
            map.put("regionId", region.getId());
        }
        map.put("address", address);
        map.put("grade", grade);
        map.put("cutoff", cutoff);
        map.put("intro", intro);
        map.put("time", time);
        return JSONUtils.toJSONString(map);
    }

    public String getGradeDisplay() {
        if (grade != null) {
            if (grade == -1) {
                return "待审核";
            } else if (grade == 1) {
                return "审核通过";
            } else if (grade == 2) {
                return "显示";
            } else if (grade == 3) {
                return "强力推荐";
            }
        }
        return "";
    }

    public BigDecimal getRealPrice() {
        //相乘
        if (cutoff != null && price != null) {
            return price.multiply(new BigDecimal(cutoff));
        }
        return null;
    }


}